package cn.mux.jdk8.local;

import java.text.ChoiceFormat;
import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;


/*
 * 国际化   和  格式化
 */
public class Hello {
	public static void main(String[] args) {
		/**
		 * 国际化
		 * 
		 * native2ascii mess.properties mess_zh_CN.properties
		 */
		Locale myLocale = Locale.getDefault(Locale.Category.FORMAT);
		ResourceBundle bundle = ResourceBundle.getBundle("mess",myLocale);
		System.out.println(bundle.getString("hello"));
		
		
		/**
		 * 格式化
		 */
		Locale locale = Locale.getDefault(Locale.Category.FORMAT);
		ResourceBundle bundle2 = ResourceBundle.getBundle("mymess",locale);
		String msg = bundle2.getString("msg");
		System.out.println(MessageFormat.format(msg,"devin",new Date()));
		
		
		/**
		 * MessageFormat
		 */
		
	/*	int fileCount = 1273;
		 String diskName = "MyDisk";
		 Object[] testArgs = {new Long(fileCount), diskName};

		 MessageFormat form = new MessageFormat(
		     "The disk \"{1}\" contains {0} file(s).");

		 System.out.println(form.format(testArgs));
		 */
		 
		 MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}.");
		 double[] filelimits = {0,1,2};
		 String[] filepart = {"no files","one file","{0,number} files"};
		 ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
		 form.setFormatByArgumentIndex(0, fileform);

		 int fileCount = 1273;
		 String diskName = "MyDisk";
		 Object[] testArgs = {new Long(fileCount), diskName};

		 System.out.println(form.format(testArgs));


		
	}
}
